#include "BallListener.h"
#include "Ball.h"
#include "EntityCategory.h"
#include "Monster.h"
#include <string>


void BallListener::BeginContact(b2Contact* contact)
{

	int userDataA = contact->GetFixtureA()->GetFilterData().categoryBits;
	int userDataB = contact->GetFixtureB()->GetFilterData().categoryBits;

	if (userDataA == BALL && userDataB == MONSTER)
	{

		void* dataA = contact->GetFixtureA()->GetBody()->GetUserData();
		Ball* nameA = static_cast<Ball*>(dataA);

		void* dataB = contact->GetFixtureB()->GetBody()->GetUserData();
		Monster* monster = static_cast<Monster*>(dataB);

		monster->hit(5, nameA->getLocation());
	}
	else if (userDataA == MONSTER && userDataB == BALL)
	{
		void* dataA = contact->GetFixtureA()->GetBody()->GetUserData();
		Monster* monster = static_cast<Monster*>(dataA);

		void* dataB = contact->GetFixtureB()->GetBody()->GetUserData();
		Ball* nameB = static_cast<Ball*>(dataB);

		monster->hit(5, nameB->getLocation());
	}

	if (userDataA == BALL)
	{
		void* dataA = contact->GetFixtureA()->GetBody()->GetUserData();
		Ball* nameA = static_cast<Ball*>(dataA);

		if(nameA != NULL)
		{
			nameA->remove();
		}
	}

	if (userDataB == BALL)
	{
		void* dataB = contact->GetFixtureB()->GetBody()->GetUserData();

		Ball* nameB = static_cast<Ball*>(dataB);

		if (nameB != NULL)
		{
			nameB->remove();
		}
	}

	

	

	


}

void BallListener::EndContact(b2Contact* contact)
{

}